﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using CE.Mail;
using CE.Image;
using CE.Database;
using CE.AreaCountry;
using CE.Global;
using CE.PersonalAccident;
using CE.PostCode;
using CE.TravelInsurance;
using CE.User;
using CE.Security;
using CE.StreetDirectory;
using CE.Payment;

public partial class travel_insurance_liberty_proposal_form : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        //if (Session[CE.Global.General.UserId] != null && Session[CE.Global.General.UserTypeId] != null)
        //{
        //    if (Convert.ToInt32(Session[CE.Global.General.UserTypeId]) !=
        //         Convert.ToInt32(CE.Global.CEUserType.Customer) && Convert.ToInt32(Session[CE.Global.General.UserTypeId]) !=
        //         Convert.ToInt32(CE.Global.CEUserType.Provider))
        //    {
        //        Response.Redirect("~/travel_insurance/travel_quote.aspx");
        //    }
        //}
        //else
        //{
        //    Response.Redirect("~/travel_insurance/travel_quote.aspx");
        //}
        if (Request.QueryString["mtaid"] != null && Request.QueryString["mpid"] != null
            && Request.QueryString["muid"] != null && Request.QueryString["mtarid"] != null && Request.QueryString["mplan"] != null)
        {
            if (Session["PlanType"] == null)
                Session["PlanType"] = Request.QueryString["mplan"].ToString();

            Session[CE.Global.General.TAId] = Request.QueryString["mtaid"].ToString();
            Session[General.ProviderCompanyId] = Request.QueryString["mpid"].ToString();
            Session[CE.Global.General.TAResultId] = Request.QueryString["mtarid"].ToString();

            if (Request.QueryString["muid"].ToString() != "0")
                Session[General.UserId] = Request.QueryString["muid"].ToString();
        }

        if (Session[CE.Global.General.TAId] == null)
        {
            Response.Redirect("~/travel-insurance/travel-quote.aspx");
        }

        if (Session[CE.Global.General.TAId] != null)
        {
            if (Session[General.ProviderCompanyId] == null)
            {
                Response.Redirect("~/travel-insurance/results.aspx");
            }

            if (Session[General.ProviderCompanyId].ToString() != "29")
            {
                Response.Redirect("~/travel-insurance/results.aspx");
            }
        }
        else
        {
            Response.Redirect("~/user/viewresulthistory.aspx");
        }


        if (!Page.IsPostBack)
        {
            lblProvider.Text = "Liberty Insurance";
            //ClearSession();
            ChangeDateSettings();
            LoadSummary();

            #region Validation Effect
            txtFullname.Attributes.Add("onblur", "ShowValidationEffect('" + txtFullname.ClientID + "','" + rfvFullname.ClientID + "')");
            //txtEmployersBusiness.Attributes.Add("onblur", "ShowValidationEffect('" + txtUnit2.ClientID + "','" + rfvEmployersBusiness.ClientID + "')");
            //txtNRICPass.Attributes.Add("onblur", "ShowValidationEffect('" + txtNRICPass.ClientID + "','" + rfvNRICPass.ClientID +"')");
            txtEmailAddress.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtEmailAddress.ClientID + "','" + rfvEmailAddress.ClientID + "','" + revEmailAddress.ClientID + "')");
            //ddlTravellerToInsure.Attributes.Add("onblur", "ShowValidationEffect('" + ddlTravellerToInsure.ClientID + "','" + rfvravellerToInsure.ClientID + "')");
            //txtPostCode.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtPostCode.ClientID + "','" + rfvPCode.ClientID + "','" + revPCode.ClientID + "')");
            //txtAddress.Attributes.Add("onblur", "ShowValidationEffect('" + txtAddress.ClientID + "','" + rfvAddress.ClientID + "')");

            txtNameoftheCard.Attributes.Add("onblur", "ShowValidationEffect('" + txtNameoftheCard.ClientID + "','" + rfvNameoftheCard.ClientID + "')");
            txtIssuingBank.Attributes.Add("onblur", "ShowValidationEffect('" + txtIssuingBank.ClientID + "','" + rfvIssuingBank.ClientID + "')");
            txtCardNo1.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtCardNo1.ClientID + "','" + rfvCardNo1.ClientID + "','" + revCardNo1.ClientID + "')");
            txtCardNo2.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtCardNo2.ClientID + "','" + rfvCardNo2.ClientID + "','" + revCardNo2.ClientID + "')");
            txtCardNo3.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtCardNo3.ClientID + "','" + rfvCardNo3.ClientID + "','" + revCardNo3.ClientID + "')");
            txtCardNo4.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtCardNo4.ClientID + "','" + rfvCardNo4.ClientID + "','" + revCardNo4.ClientID + "')");
            ddlCardExpiryMonth.Attributes.Add("onblur", "ShowValidationEffect('" + ddlCardExpiryMonth.ClientID + "','" + rfvCardExpiryMonth.ClientID + "')");
            ddlCardExpiryYear.Attributes.Add("onblur", "ShowValidationEffect('" + ddlCardExpiryYear.ClientID + "','" + rfvCardExpiryYear.ClientID + "')");

            txtNameInsured.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtNameInsured.ClientID + "','" + rfvNameInsured.ClientID + "','" + revNameInsured.ClientID + "')");
            txtNameAdult2orSpouse.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtNameAdult2orSpouse.ClientID + "','" + rfvNameAdult2orSpouse.ClientID + "','" + revNameAdult2orSpouse.ClientID + "')");
            txtChildName1.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtChildName1.ClientID + "','" + rfvChildName1.ClientID + "','" + revChildName1.ClientID + "')");
            txtChildName2.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtChildName2.ClientID + "','" + rfvChildName2.ClientID + "','" + revChildName2.ClientID + "')");
            txtChildName3.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtChildName3.ClientID + "','" + rfvChildName3.ClientID + "','" + revChildName3.ClientID + "')");
            txtChildName4.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtChildName4.ClientID + "','" + rfvChildName4.ClientID + "','" + revChildName4.ClientID + "')");
            txtChildName5.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtChildName5.ClientID + "','" + rfvChildName5.ClientID + "','" + revChildName5.ClientID + "')");

            rdoVisa.Attributes.Add("onblur", "CheckCardTypeValidationCss();");
            rdoMasterCard.Attributes.Add("onblur", "CheckCardTypeValidationCss();");

            #endregion

            //txtEmployersBusiness.Attributes.Add("onkeyup", "ShowHideDiv('divPaymentMode',true);");

            int _year;
            int startyear = CE.Global.General.GetUTCDateTime().Year;
            int endyear = CE.Global.General.GetUTCDateTime().Year + 10;
            for (_year = endyear; _year >= startyear; _year--)
            {
                ddlCardExpiryYear.Items.Insert(0, new ListItem(_year.ToString("0000"), _year.ToString("00")));
            }
            ddlCardExpiryYear.Items.Insert(0, new ListItem("yyyy", "-1"));

            Session[General.ViewedDetailsId] = LogUserViewedHistory().ToString();

            if (Session[General.UserId] != null)
            {
                ShowUserDetails();
            }
            else if (Session[General.TAPersonnelId] != null
               && Session[General.TAUserName] != null
               && Session[General.TAPhoneNo] != null
               && Session[General.TAEmail] != null)
            {
                txtFullname.Text = Session[General.TAUserName].ToString();
                txtMobileNo.PhoneNo = Session[General.TAPhoneNo].ToString();
                txtEmailAddress.Text = Session[General.TAEmail].ToString();
            }

            if (chkInsurerNameAgreed.Checked == true)
            {
                rfvNameInsured.Enabled = false;
                revNameInsured.Enabled = false;
                ddlNRICInsured.IsEnableValidation(false);
                usrDOBInsured.IsEnableValidation(false);
                ddlGenderInsured.IsEnableValidation(false);
                ddlNationalityInsured.IsEnableValidation(false);
                //ddlRelationshipInsured.IsEnableValidation(false);
                ddlOccupationInsured.IsEnableValidation(false);
            }
            else
            {
                rfvNameInsured.Enabled = true;
                revNameInsured.Enabled = true;
                ddlNRICInsured.IsEnableValidation(true);
                usrDOBInsured.IsEnableValidation(true);
                ddlGenderInsured.IsEnableValidation(true);
                ddlNationalityInsured.IsEnableValidation(true);
                //ddlRelationshipInsured.IsEnableValidation(true);
                ddlOccupationInsured.IsEnableValidation(true);
            }
        }

        if (rdoVisa.Checked || rdoMasterCard.Checked) txtCardType.Text = "1";


    }

    protected void LoadSummary()
    {
        Int64 TAId = 0;

        TAApplicantSearchDB _taapplicantsearchdb = new TAApplicantSearchDB();
        TAApplicantSearch _taapplicantsearch = new TAApplicantSearch();

        if (Session[General.TAId] != null)
            TAId = Convert.ToInt64(Session[General.TAId]);

        _taapplicantsearch = _taapplicantsearchdb.GetTAApplicantSearchItem(TAId);

        if (_taapplicantsearch != null)
        {
            string convertno = General.GetRefNumber(Convert.ToInt64(Session[General.TAId].ToString()));
            lblQref.Text = "TIL" + convertno;
            lblPolicyType.Text = GetPolicy(_taapplicantsearch.PlanType.ToString());
            lblTrip.Text = _taapplicantsearch.TripType.ToString();
            lblCover.Text = _taapplicantsearch.CoverageLevel.ToString();
            lblCoverageType.Text = GetCoverage(_taapplicantsearch.TripType.ToString());
            lblCoverage.Text = _taapplicantsearch.CoverageLevel.ToString();
            lblTotalPremium.Text = "$ " + _taapplicantsearch.TotalPremium.ToString();
            lblNoOfTravellers.Text = _taapplicantsearch.NoOfTravellers.ToString();
            inNoOfTravellers.Value = _taapplicantsearch.NoOfTravellers.ToString();
            //lblInsCoverage.Text = GetPlanName(_taapplicantsearch.PlanType.ToString(), _taapplicantsearch.CoverageLevel.ToString());
            lblDuration.Text = _taapplicantsearch.Duration.ToString();
            lblAdultAge.Text = _taapplicantsearch.AdultAge.ToString();
            lblChildAge.Text = _taapplicantsearch.ChildAge.ToString();

            usrDOBInsured.Day = _taapplicantsearch.DOBAdult1.Day;
            usrDOBInsured.Month = _taapplicantsearch.DOBAdult1.Month;
            usrDOBInsured.Year = _taapplicantsearch.DOBAdult1.Year;

            usrDOBAdult2orSpouse.Day = _taapplicantsearch.DOBAdult2.Day;
            usrDOBAdult2orSpouse.Month = _taapplicantsearch.DOBAdult2.Month;
            usrDOBAdult2orSpouse.Year = _taapplicantsearch.DOBAdult2.Year;

            if (_taapplicantsearch.TripType == "A")
            {
                lblPeriodOfCoverage.Text = String.Format("{0:dd/MM/yyyy}", _taapplicantsearch.StartDate);
                lblStart.Text = _taapplicantsearch.StartDate.ToString();
                lblEnd.Text = _taapplicantsearch.StartDate.ToString();
            }
            else
            {
                lblPeriodOfCoverage.Text = String.Format("{0:dd/MM/yyyy} To {1:dd/MM/yyyy}", _taapplicantsearch.StartDate, _taapplicantsearch.EndDate);
                lblStart.Text = _taapplicantsearch.StartDate.ToString();
                lblEnd.Text = _taapplicantsearch.EndDate.ToString();

            }

            if (_taapplicantsearch.AreaID != 0)
                lblDestination.Text = GetAreaName(_taapplicantsearch.AreaID);
            else
                lblDestination.Text = GetCountryName(_taapplicantsearch.CountryID);

            txtNoofAdults.Text = _taapplicantsearch.NoofAdults.ToString();
            txtNoofChilds.Text = _taapplicantsearch.NoofChilds.ToString();
            Int32 _AdultCount = Convert.ToInt32(txtNoofAdults.Text.Trim());
            Int32 _ChildCount = Convert.ToInt32(txtNoofChilds.Text.Trim());

            if (_AdultCount > 1)
            {
                pnlAdult.Visible = true;
                rfvNameAdult2orSpouse.Enabled = true;
                revNameAdult2orSpouse.Enabled = true;
                ddlNRICAdult2orSpouse.IsEnableValidation(true);
                usrDOBAdult2orSpouse.IsEnableValidation(true);
                ddlGenderAdult2orSpouse.IsEnableValidation(true);
                ddlNationalityAdult2orSpouse.IsEnableValidation(true);
                ddlRelationshipAdult2orSpouse.IsEnableValidation(true);
                ddlOccupationAdult2orSpouse.IsEnableValidation(true);
            }
            else
            {
                pnlAdult.Visible = false;
                rfvNameAdult2orSpouse.Enabled = false;
                revNameAdult2orSpouse.Enabled = false;
                ddlNRICAdult2orSpouse.IsEnableValidation(false);
                usrDOBAdult2orSpouse.IsEnableValidation(false);
                ddlGenderAdult2orSpouse.IsEnableValidation(false);
                ddlNationalityAdult2orSpouse.IsEnableValidation(false);
                ddlRelationshipAdult2orSpouse.IsEnableValidation(false);
                ddlOccupationAdult2orSpouse.IsEnableValidation(false);
            }
            if (_ChildCount > 0)
            {
                ddlChildDOB1.Day = _taapplicantsearch.DOBChild1.Day;
                ddlChildDOB1.Month = _taapplicantsearch.DOBChild1.Month;
                ddlChildDOB1.Year = _taapplicantsearch.DOBChild1.Year;

                ddlChildDOB2.Day = _taapplicantsearch.DOBChild2.Day;
                ddlChildDOB2.Month = _taapplicantsearch.DOBChild2.Month;
                ddlChildDOB2.Year = _taapplicantsearch.DOBChild2.Year;

                ddlChildDOB3.Day = _taapplicantsearch.DOBChild3.Day;
                ddlChildDOB3.Month = _taapplicantsearch.DOBChild3.Month;
                ddlChildDOB3.Year = _taapplicantsearch.DOBChild3.Year;

                ddlChildDOB4.Day = _taapplicantsearch.DOBChild4.Day;
                ddlChildDOB4.Month = _taapplicantsearch.DOBChild4.Month;
                ddlChildDOB4.Year = _taapplicantsearch.DOBChild4.Year;

                ddlChildDOB5.Day = _taapplicantsearch.DOBChild5.Day;
                ddlChildDOB5.Month = _taapplicantsearch.DOBChild5.Month;
                ddlChildDOB5.Year = _taapplicantsearch.DOBChild5.Year;

                ddlChildDOB6.Day = _taapplicantsearch.DOBChild6.Day;
                ddlChildDOB6.Month = _taapplicantsearch.DOBChild6.Month;
                ddlChildDOB6.Year = _taapplicantsearch.DOBChild6.Year;


                pnlChildsParticulars.Visible = true;
                if (_ChildCount == 1)
                {
                    pnlChild1.Visible = true;
                    pnlChild2.Visible = false;
                    pnlChild3.Visible = false;
                    pnlChild4.Visible = false;
                    pnlChild5.Visible = false;
                    pnlChild6.Visible = false;

                    ValidateChild1(true);
                    ValidateChild2(false);
                    ValidateChild3(false);
                    ValidateChild4(false);
                    ValidateChild5(false);
                    ValidateChild6(false);
                }
                else if (_ChildCount == 2)
                {
                    pnlChild1.Visible = true;
                    pnlChild2.Visible = true;
                    pnlChild3.Visible = false;
                    pnlChild4.Visible = false;
                    pnlChild5.Visible = false;
                    pnlChild6.Visible = false;

                    ValidateChild1(true);
                    ValidateChild2(true);
                    ValidateChild3(false);
                    ValidateChild4(false);
                    ValidateChild5(false);
                    ValidateChild6(false);
                }
                else if (_ChildCount == 3)
                {
                    pnlChild1.Visible = true;
                    pnlChild2.Visible = true;
                    pnlChild3.Visible = true;
                    pnlChild4.Visible = false;
                    pnlChild5.Visible = false;
                    pnlChild6.Visible = false;

                    ValidateChild1(true);
                    ValidateChild2(true);
                    ValidateChild3(true);
                    ValidateChild4(false);
                    ValidateChild5(false);
                    ValidateChild6(false);
                }
                else if (_ChildCount == 4)
                {
                    pnlChild1.Visible = true;
                    pnlChild2.Visible = true;
                    pnlChild3.Visible = true;
                    pnlChild4.Visible = true;
                    pnlChild5.Visible = false;
                    pnlChild6.Visible = false;

                    ValidateChild1(true);
                    ValidateChild2(true);
                    ValidateChild3(true);
                    ValidateChild4(true);
                    ValidateChild5(false);
                    ValidateChild6(false);
                }
                else if (_ChildCount == 5)
                {
                    pnlChild1.Visible = true;
                    pnlChild2.Visible = true;
                    pnlChild3.Visible = true;
                    pnlChild4.Visible = true;
                    pnlChild5.Visible = true;
                    pnlChild6.Visible = false;

                    ValidateChild1(true);
                    ValidateChild2(true);
                    ValidateChild3(true);
                    ValidateChild4(true);
                    ValidateChild5(true);
                    ValidateChild6(false);
                }
                else if (_ChildCount == 6)
                {
                    pnlChild1.Visible = true;
                    pnlChild2.Visible = true;
                    pnlChild3.Visible = true;
                    pnlChild4.Visible = true;
                    pnlChild5.Visible = true;
                    pnlChild6.Visible = true;

                    ValidateChild1(true);
                    ValidateChild2(true);
                    ValidateChild3(true);
                    ValidateChild4(true);
                    ValidateChild5(true);
                    ValidateChild6(true);
                }
            }
            else
            {
                pnlChildsParticulars.Visible = false;
                ValidateChild1(false);
                ValidateChild2(false);
                ValidateChild3(false);
                ValidateChild4(false);
                ValidateChild5(false);
                ValidateChild6(false);
            }
        }
    }

    protected string GetPlanName(string plantype, string coveragelevel)
    {
        string planname = "";
        TAQuoteResult _taresult = new TAQuoteResult();
        TAQuoteResultDB _tadb = new TAQuoteResultDB();

        _taresult = _tadb.GetTASelectSingleItemSelected(Convert.ToInt64(Session[CE.Global.General.ProviderCompanyId].ToString()), GetPolicy(plantype), coveragelevel);

        if (_taresult != null)
        {
            planname = _taresult.PlanName;
        }

        return planname;
    }

    protected string GetPolicy(string covertype)
    {
        string policy = "family";

        if (covertype == "IND")
        {
            policy = "Individual";
        }
        else if (covertype == "INS")
        {
            policy = "Individual + Spouse";
        }
        else if (covertype == "INC")
        {
            policy = "Individual + Child";
        }
        else if (covertype == "FML")
        {
            policy = "Family";
        }

        return policy;
    }

    protected string GetCoverage(string coverage)
    {
        string cover = "Single Trip";

        if (coverage == "A")
            cover = "Annual Multi-trip";

        return cover;
    }

    protected string GetCoverageLevel(string coverage)
    {
        string coveragelevel = "Standard";

        if (coverage == "STD")
            coveragelevel = "Standard";
        else if (coverage == "MED")
            coveragelevel = "Medium";
        else if (coverage == "HGH")
            coveragelevel = "High";

        return coveragelevel;
    }

    protected string GetAreaName(Int64 areaid)
    {
        string Area = "";

        AreaInfo _areainfo = new AreaInfo();
        AreaInfoDB _areainfodb = new AreaInfoDB();

        _areainfo = _areainfodb.GetAreaInfo(areaid);

        Area = _areainfo.Description;

        return Area;

    }

    protected string GetCountryName(Int64 countryid)
    {
        string Country = "";

        CountryInfo _countryinfo = new CountryInfo();
        CountryInfoDB _countryinfodb = new CountryInfoDB();

        _countryinfo = _countryinfodb.GetCountryInfo(countryid);

        Country = _countryinfo.Description;

        return Country;

    }

    protected void ibtSubmit_Click(object sender, ImageClickEventArgs e)
    {
        CheckValidation();
        ChangeValidationEffectServerSide("travel_insurance");

        if (IsValid)
        {
            Int64 _tamoreresult = 0;
            TAMoreDetailLiberty _tamoredetailiberty = new TAMoreDetailLiberty();
            TAMoreDetailLibertyDB _tamoredetailibertydb = new TAMoreDetailLibertyDB();


            _tamoredetailiberty.cetaMoreDetailId = 0;
            _tamoredetailiberty.cetaInsId = Convert.ToInt64(Session[General.TAResultId].ToString());
            _tamoredetailiberty.cetaId = Convert.ToInt64(Session[General.TAId].ToString()); //TAAppSeaID 
            _tamoredetailiberty.ProviderCompanyId = Convert.ToInt64(Session[General.ProviderCompanyId].ToString());
            _tamoredetailiberty.Name = txtFullname.Text.ToUpper();
            _tamoredetailiberty.PostalCode = txtPostCode.Text.Trim();
            _tamoredetailiberty.UnitNo = txtUnit1.Text.Trim();
            _tamoredetailiberty.HomeNo = txtUnit2.Text.Trim();
            _tamoredetailiberty.Address = txtAddress.Text.Trim();
            //_tamoredetailiberty.NRICNo = txtNRICPass.Text;
            _tamoredetailiberty.NRICNo = ddlNRIC.GetIdNumber();
            _tamoredetailiberty.Nationality = ddlNationality.GetNationality();
            _tamoredetailiberty.MobileNo = txtMobileNo.GetPhoneNo();
            _tamoredetailiberty.HomePhoneNo = txtResidentialPhoneNo.GetPhoneNo();
            _tamoredetailiberty.OfficePhoneNo = txtOfficeNo.GetPhoneNo();
            _tamoredetailiberty.FaxNo = "";
            _tamoredetailiberty.Gender = usrGender.GetGender();
            _tamoredetailiberty.MaritalStatus = ddlMaritalStatus.GetMaritalStatus();
            _tamoredetailiberty.Occupation = usrOccupation.GetOccupation();
            _tamoredetailiberty.EmployersBusiness = ""; // txtEmployersBusiness.Text.Trim();
            _tamoredetailiberty.EmpName = "";
            //_tamoredetailiberty.PlanName = lblInsCoverage.Text;
            _tamoredetailiberty.PlanType = lblPolicyType.Text;
            _tamoredetailiberty.TripType = lblTrip.Text;
            _tamoredetailiberty.CoverageLevel = lblCover.Text;
            _tamoredetailiberty.Country = lblDestination.Text;
            _tamoredetailiberty.Area = lblDestination.Text;
            _tamoredetailiberty.Duration = lblDuration.Text;
            _tamoredetailiberty.StartDate = DateTime.Parse(lblStart.Text);
            _tamoredetailiberty.EndDate = DateTime.Parse(lblEnd.Text);
            _tamoredetailiberty.AdultAge = Convert.ToInt32(lblAdultAge.Text);
            _tamoredetailiberty.ChildAge = Convert.ToInt32(lblChildAge.Text);
            _tamoredetailiberty.NoOfTraveller = Convert.ToInt32(lblNoOfTravellers.Text);
            _tamoredetailiberty.TotalPremium = float.Parse(lblTotalPremium.Text.Remove(0, 2));
            _tamoredetailiberty.PamentType = "CreditCard";

            if (Session[General.UserId] != null)
            {
                _tamoredetailiberty.DOB = usrDOB.GetDate();
                _tamoredetailiberty.RefCEUserId = Convert.ToInt64(Session[General.UserId].ToString());
            }
            else
            {
                _tamoredetailiberty.RefCEUserId = Convert.ToInt64(Session[CE.Global.General.TAPersonnelId].ToString());

                //get current values
                TAApplicantSearchDB _taapplicantsearchdb = new TAApplicantSearchDB();
                TAApplicantSearch _taapplicantsearch = new TAApplicantSearch();
                Int64 TAId = 0;

                if (Session[General.TAId] != null)
                    TAId = Convert.ToInt64(Session[General.TAId]);

                _taapplicantsearch = _taapplicantsearchdb.GetTAApplicantSearchItem(TAId);

                if (_taapplicantsearch != null)
                {
                    _tamoredetailiberty.DOB = _taapplicantsearch.DOBAdult1;
                }
            }

            _tamoredetailiberty.ViewedDetailId = Convert.ToInt64(Session[General.ViewedDetailsId].ToString());
            _tamoredetailiberty.Status = true;
            _tamoredetailiberty.Info1 = "";
            _tamoredetailiberty.Info2 = Session[General.TAId].ToString(); //AppSeaID
            _tamoredetailiberty.Info3 = txtEmailAddress.Text;

            _tamoreresult = _tamoredetailibertydb.Insert(_tamoredetailiberty);


            Int64 TATraId = 0;
            if (_tamoreresult > 0)
            {
                Int64 _paymentresult = 0;
                Payment _payment = new Payment();
                PaymentDB _paymentdb = new PaymentDB();

                _payment.CXPaymentId = 0;
                _payment.RefId = Convert.ToInt64(Session[General.TAId].ToString()); //_tamoreresult; // 
                _payment.ProviderCompanyId = Convert.ToInt64(Session[General.ProviderCompanyId].ToString());
                _payment.InsuranceType = "TI";
                _payment.NameoftheCard = txtNameoftheCard.Text.ToUpper();
                _payment.IssuingBankName = txtIssuingBank.Text.Trim();
                _payment.CreditCardNo = txtCardNo1.Text.Trim() + "" + txtCardNo2.Text.Trim() + "" + txtCardNo3.Text.Trim() + "" + txtCardNo4.Text.Trim();
                _payment.CardExpiryMonth = ddlCardExpiryMonth.Text;
                _payment.CardExpiryYear = ddlCardExpiryYear.Text;
                if (rdoVisa.Checked == true)
                {
                    _payment.CardType = "Visa";
                }
                else
                {
                    _payment.CardType = "MasterCard";
                }
                _payment.Status = true;
                if (Session[CE.Global.General.UserId] != null)
                {
                    _payment.RefCEUserId = Convert.ToInt64(Session[CE.Global.General.UserId].ToString());
                }
                else
                {
                    _payment.RefCEUserId = Convert.ToInt64(Session[CE.Global.General.TAPersonnelId].ToString());
                }
                _paymentresult = _paymentdb.Insert(_payment);

                if (_paymentresult > 0)
                {

                    //Save Travellers to Insure

                    int NoOfTravellers = 0;
                    int NoOfAdults = 0;
                    int NoOfChilds = 0;

                    string idtype = "";
                    string gender = "";
                    string fullname = "";
                    string idnum = "";
                    DateTime birthday = CE.Global.General.GetUTCDateTime();
                    string nationality = "";
                    string relationship = "";
                    string occupation = "";
                    string salutation = "";

                    NoOfTravellers = Convert.ToInt32(lblNoOfTravellers.Text.Trim());
                    NoOfAdults = Convert.ToInt32(txtNoofAdults.Text.Trim());
                    NoOfChilds = Convert.ToInt32(txtNoofChilds.Text.Trim());

                    TATravellersToInsure _tatravellerstoinsure = new TATravellersToInsure();
                    TATravellersToInsureDB _tatravellerstoinsuredb = new TATravellersToInsureDB();

                    for (int i = 1; i <= NoOfTravellers; i++)
                    {
                        if (i == 1)
                        {
                            if (chkInsurerNameAgreed.Checked == false)
                            {
                                fullname = txtNameInsured.Text.ToUpper();
                                idnum = ddlNRICInsured.GetIdNumber();
                                birthday = usrDOBInsured.GetDate();
                                nationality = ddlNationalityInsured.GetNationality();
                                relationship = "Proposer";
                                gender = ddlGenderInsured.GetGender();
                                occupation = ddlOccupationInsured.GetOccupation();
                            }
                            else if (chkInsurerNameAgreed.Checked == true)
                            {
                                fullname = txtFullname.Text.ToUpper();
                                idnum = ddlNRIC.GetIdNumber();
                                birthday = usrDOBInsured.GetDate();
                                nationality = ddlNationality.GetNationality();
                                relationship = "Proposer";
                                gender = usrGender.GetGender();
                                occupation = usrOccupation.GetOccupation();
                            }
                        }
                        if (NoOfAdults == 2)
                        {
                            if (i == 2)
                            {
                                fullname = txtNameAdult2orSpouse.Text.ToUpper();
                                idnum = ddlNRICAdult2orSpouse.GetIdNumber();
                                birthday = usrDOBAdult2orSpouse.GetDate();
                                nationality = ddlNationalityAdult2orSpouse.GetNationality();
                                relationship = ddlRelationshipAdult2orSpouse.GetRelationship();
                                gender = ddlGenderAdult2orSpouse.GetGender();
                                occupation = ddlOccupationAdult2orSpouse.GetOccupation();
                            }
                            if (i == 3)
                            {
                                fullname = txtChildName1.Text.ToUpper();
                                idnum = ddlChildNRIC1.GetIdNumber();
                                birthday = ddlChildDOB1.GetDate();
                                nationality = ddlChildNationality1.GetNationality();
                                relationship = ddlChildRelationship1.GetRelationship();
                                gender = ddlGenderChild1.GetGender();
                                occupation = "-1";
                            }
                            if (i == 4)
                            {
                                fullname = txtChildName2.Text.ToUpper();
                                idnum = ddlChildNRIC2.GetIdNumber();
                                birthday = ddlChildDOB2.GetDate();
                                nationality = ddlChildNationality2.GetNationality();
                                relationship = ddlChildRelationship2.GetRelationship();
                                gender = ddlGenderChild2.GetGender();
                                occupation = "-1";
                            }
                            if (i == 5)
                            {
                                fullname = txtChildName3.Text.ToUpper();
                                idnum = ddlChildNRIC3.GetIdNumber();
                                birthday = ddlChildDOB3.GetDate();
                                nationality = ddlChildNationality3.GetNationality();
                                relationship = ddlChildRelationship3.GetRelationship();
                                gender = ddlGenderChild3.GetGender();
                                occupation = "-1";
                            }
                            if (i == 6)
                            {
                                fullname = txtChildName4.Text.ToUpper();
                                idnum = ddlChildNRIC4.GetIdNumber();
                                birthday = ddlChildDOB4.GetDate();
                                nationality = ddlChildNationality4.GetNationality();
                                relationship = ddlChildRelationship4.GetRelationship();
                                gender = ddlGenderChild4.GetGender();
                                occupation = "-1";
                            }
                            if (i == 7)
                            {
                                fullname = txtChildName5.Text.ToUpper();
                                idnum = ddlChildNRIC5.GetIdNumber();
                                birthday = ddlChildDOB5.GetDate();
                                nationality = ddlChildNationality5.GetNationality();
                                relationship = ddlChildRelationship5.GetRelationship();
                                gender = ddlGenderChild5.GetGender();
                                occupation = "-1";
                            }
                            if (i == 8)
                            {
                                fullname = txtChildName6.Text.ToUpper();
                                idnum = ddlChildNRIC6.GetIdNumber();
                                birthday = ddlChildDOB6.GetDate();
                                nationality = ddlChildNationality6.GetNationality();
                                relationship = ddlChildRelationship6.GetRelationship();
                                gender = ddlGenderChild6.GetGender();
                                occupation = "-1";
                            }
                        }
                        else
                        {
                            if (i == 2)
                            {
                                fullname = txtChildName1.Text.ToUpper();
                                idnum = ddlChildNRIC1.GetIdNumber();
                                birthday = ddlChildDOB1.GetDate();
                                nationality = ddlChildNationality1.GetNationality();
                                relationship = ddlChildRelationship1.GetRelationship();
                                gender = ddlGenderChild1.GetGender();
                                occupation = "-1";
                            }
                            if (i == 3)
                            {
                                fullname = txtChildName2.Text.ToUpper();
                                idnum = ddlChildNRIC2.GetIdNumber();
                                birthday = ddlChildDOB2.GetDate();
                                nationality = ddlChildNationality2.GetNationality();
                                relationship = ddlChildRelationship2.GetRelationship();
                                gender = ddlGenderChild2.GetGender();
                                occupation = "-1";
                            }
                            if (i == 4)
                            {
                                fullname = txtChildName3.Text.ToUpper();
                                idnum = ddlChildNRIC3.GetIdNumber();
                                birthday = ddlChildDOB3.GetDate();
                                nationality = ddlChildNationality3.GetNationality();
                                relationship = ddlChildRelationship3.GetRelationship();
                                gender = ddlGenderChild3.GetGender();
                                occupation = "-1";
                            }
                            if (i == 5)
                            {
                                fullname = txtChildName4.Text.ToUpper();
                                idnum = ddlChildNRIC4.GetIdNumber();
                                birthday = ddlChildDOB4.GetDate();
                                nationality = ddlChildNationality4.GetNationality();
                                relationship = ddlChildRelationship4.GetRelationship();
                                gender = ddlGenderChild4.GetGender();
                                occupation = "-1";
                            }
                            if (i == 6)
                            {
                                fullname = txtChildName5.Text.ToUpper();
                                idnum = ddlChildNRIC5.GetIdNumber();
                                birthday = ddlChildDOB5.GetDate();
                                nationality = ddlChildNationality5.GetNationality();
                                relationship = ddlChildRelationship5.GetRelationship();
                                gender = ddlGenderChild5.GetGender();
                                occupation = "-1";
                            }
                            if (i == 7)
                            {
                                fullname = txtChildName6.Text.ToUpper();
                                idnum = ddlChildNRIC6.GetIdNumber();
                                birthday = ddlChildDOB6.GetDate();
                                nationality = ddlChildNationality6.GetNationality();
                                relationship = ddlChildRelationship6.GetRelationship();
                                gender = ddlGenderChild6.GetGender();
                                occupation = "-1";
                            }
                        }
                        _tatravellerstoinsure.TATraId = 0;
                        _tatravellerstoinsure.TAPersonnelId = _tamoreresult;
                        _tatravellerstoinsure.ProviderCompanyId = Convert.ToInt64(Session[General.ProviderCompanyId].ToString());
                        _tatravellerstoinsure.Salutation = salutation;
                        _tatravellerstoinsure.Fullname = fullname;
                        _tatravellerstoinsure.IDType = idtype;
                        _tatravellerstoinsure.IDNumber = idnum;
                        _tatravellerstoinsure.Gender = gender;
                        _tatravellerstoinsure.Birthday = birthday;
                        _tatravellerstoinsure.Nationality = nationality;
                        _tatravellerstoinsure.Relationship = relationship;
                        _tatravellerstoinsure.Occupation = occupation;
                        _tatravellerstoinsure.Info1 = "LIBERTY";

                        if (Session[General.UserId] != null)
                            _tatravellerstoinsure.RefCEUserId = Convert.ToInt64(Session[General.UserId].ToString());
                        else
                            _tatravellerstoinsure.RefCEUserId = Convert.ToInt64(Session[CE.Global.General.TAPersonnelId].ToString());

                        _tatravellerstoinsure.ViewedDetailId = Convert.ToInt64(Session[General.ViewedDetailsId].ToString());
                        _tatravellerstoinsure.Status = true;

                        TATraId = _tatravellerstoinsuredb.Insert(_tatravellerstoinsure);
                    }

                    if (TATraId > 0)
                    {
                        ProposalNotification();
                        UserConfirmation _userconfirm = new UserConfirmation();
                        UserConfirmationDB _userconfirmdb = new UserConfirmationDB();
                        _userconfirm.ConfirmationType = "TA";
                        _userconfirm.CurrentStep = 2;
                        _userconfirm.FirstStepId = Convert.ToInt64(Session[General.TAId].ToString());

                        if (Session[General.UserId] != null)
                            _userconfirm.RefCEUserId = Convert.ToInt64(Session[General.UserId].ToString());
                        else
                            _userconfirm.RefCEUserId = Convert.ToInt64(Session[CE.Global.General.TAPersonnelId].ToString());

                        _userconfirm.Status = true;
                        _userconfirm.IsConfirm = true;
                        _userconfirm.ResultStatus = "Complete";
                        _userconfirm.IsComplete = true;
                        Int64 _result = _userconfirmdb.Insert(_userconfirm);
                        if (_result > 0)
                        {
                            string _providerid = Encode(Session[General.ProviderCompanyId].ToString());
                            string convertno = General.GetRefNumber(Convert.ToInt64(Session[General.TAId].ToString()));
                            string _RefNo = "TIL" + convertno;

                            General.ClearAllSession(this.Page, "ALL");

                            Response.Redirect("~/travel-insurance/usermessage.aspx?pcid=" + _providerid + "&ref=" + _RefNo);
                        }
                        else
                        {
                            Page.ClientScript.RegisterStartupScript(this.GetType(), "ShowMessage", "alert(\"Can't update confirmation status.\"", true);
                        }
                    }
                }
            }
        }
    }

    public string Encode(string sData)
    {
        byte[] encData_byte = new byte[sData.Length];
        encData_byte = System.Text.Encoding.UTF8.GetBytes(sData);
        string encodedData = Convert.ToBase64String(encData_byte);
        return encodedData;
    }

    private Int64 LogUserViewedHistory()
    {
        UserViewHistoryDB _userviewdb = new UserViewHistoryDB();
        return _userviewdb.LogViewedHistory("TA", Request, "Travel Insurance applicant's details.");
    }

    private void CheckValidation()
    {

        usrDOB.IsEnableValidation(false);

        txtPostCode.Text = General.ClearScriptTag(txtPostCode.Text);
        txtUnit1.Text = General.ClearScriptTag(txtUnit1.Text);
        txtUnit2.Text = General.ClearScriptTag(txtUnit2.Text);
        txtAddress.Text = General.ClearScriptTag(txtAddress.Text);


        txtNameoftheCard.Text = General.ClearScriptTag(txtNameoftheCard.Text);
        txtIssuingBank.Text = General.ClearScriptTag(txtIssuingBank.Text);
        txtCardNo1.Text = General.ClearScriptTag(txtCardNo1.Text);
        txtCardNo2.Text = General.ClearScriptTag(txtCardNo2.Text);
        txtCardNo3.Text = General.ClearScriptTag(txtCardNo3.Text);
        txtCardNo4.Text = General.ClearScriptTag(txtCardNo4.Text);

        if (chkInsurerNameAgreed.Checked == true)
        {
            rfvNameInsured.Enabled = false;
            revNameInsured.Enabled = false;
            ddlNRICInsured.IsEnableValidation(false);
            usrDOBInsured.IsEnableValidation(false);
            ddlGenderInsured.IsEnableValidation(false);
            ddlNationalityInsured.IsEnableValidation(false);
            //ddlRelationshipInsured.IsEnableValidation(false);
            ddlOccupationInsured.IsEnableValidation(false);
        }
        else
        {
            rfvNameInsured.Enabled = true;
            revNameInsured.Enabled = true;
            ddlNRICInsured.IsEnableValidation(true);
            usrDOBInsured.IsEnableValidation(true);
            ddlGenderInsured.IsEnableValidation(true);
            ddlNationalityInsured.IsEnableValidation(true);
            //ddlRelationshipInsured.IsEnableValidation(true);
            ddlOccupationInsured.IsEnableValidation(true);
        }

    }

    private void ChangeValidationEffectServerSide(string strValidationGroup)
    {
        #region Particulars of Proposer

        if (rfvFullname.Enabled && rfvFullname.ValidationGroup == strValidationGroup)
        {
            rfvFullname.Validate();
            if (rfvFullname.IsValid == false)
            {
                txtFullname.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtFullname.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtFullname.ControlStyle.CssClass = "";
        }

        if (revEmailAddress.Enabled && revEmailAddress.ValidationGroup == strValidationGroup)
        {
            if (rfvEmailAddress.IsValid)
            {
                revEmailAddress.Validate();
                if (revEmailAddress.IsValid == false)
                {
                    txtEmailAddress.ControlStyle.CssClass = "validationError";
                }
                else
                {
                    txtEmailAddress.ControlStyle.CssClass = "";
                }
            }
        }
        else
        {
            txtEmailAddress.ControlStyle.CssClass = "";

        }

        //if (revPostCode.Enabled && revPostCode.ValidationGroup == strValidationGroup)
        //{
        //    if (rfvPostCode.IsValid)
        //    {
        //        revPostCode.Validate();
        //        if (revPostCode.IsValid == false)
        //        {
        //            txtPostCode.ControlStyle.CssClass = "validationError";
        //        }
        //        else
        //        {
        //            txtPostCode.ControlStyle.CssClass = "";
        //        }
        //    }
        //}
        //else
        //{
        //    txtPostCode.ControlStyle.CssClass = "";

        //}

        if (rfvAddress.Enabled && rfvAddress.ValidationGroup == strValidationGroup)
        {
            rfvAddress.Validate();
            if (rfvAddress.IsValid == false)
            {
                txtAddress.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtAddress.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtAddress.ControlStyle.CssClass = "";
        }


        usrGender.ChangeValidationEffectServerSide(strValidationGroup);
        usrOccupation.ChangeValidationEffectServerSide(strValidationGroup);
        ddlMaritalStatus.ChangeValidationEffectServerSide(strValidationGroup);
        ddlNationality.ChangeValidationEffectServerSide(strValidationGroup);
        txtMobileNo.ChangeValidationEffectServerSide(strValidationGroup);
        txtOfficeNo.ChangeValidationEffectServerSide(strValidationGroup);
        txtResidentialPhoneNo.ChangeValidationEffectServerSide(strValidationGroup);
        usrDOBInsured.ChangeValidationEffectServerSide(strValidationGroup);
        ddlNRIC.ChangeValidationEffectServerSide(strValidationGroup);


        //if (rfvEmployersBusiness.Enabled && rfvEmployersBusiness.ValidationGroup == strValidationGroup)
        //{
        //    rfvEmployersBusiness.Validate();
        //    if (rfvEmployersBusiness.IsValid == false)
        //    {
        //        txtEmployersBusiness.ControlStyle.CssClass = "validationError";
        //    }
        //    else
        //    {
        //        txtEmployersBusiness.ControlStyle.CssClass = "";
        //    }
        //}
        //else
        //{
        //    txtEmployersBusiness.ControlStyle.CssClass = "";
        //}


        //if (rfvNRICPass.Enabled && rfvNRICPass.ValidationGroup == strValidationGroup)
        //{
        //    rfvNRICPass.Validate();
        //    if (rfvNRICPass.IsValid == false)
        //    {
        //        txtNRICPass.ControlStyle.CssClass = "validationError";
        //    }
        //    else
        //    {
        //        txtNRICPass.ControlStyle.CssClass = "";
        //    }
        //}
        //else
        //{
        //    txtNRICPass.ControlStyle.CssClass = "";
        //}


        #endregion

        #region Payment Mode


        //Name of the Card
        if (rfvNameoftheCard.Enabled && rfvNameoftheCard.ValidationGroup == strValidationGroup)
        {
            rfvNameoftheCard.Validate();
            if (rfvNameoftheCard.IsValid == false)
            {
                txtNameoftheCard.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtNameoftheCard.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtNameoftheCard.ControlStyle.CssClass = "";
        }
        //Issuing Bank
        if (rfvIssuingBank.Enabled && rfvIssuingBank.ValidationGroup == strValidationGroup)
        {
            rfvIssuingBank.Validate();
            if (rfvIssuingBank.IsValid == false)
            {
                txtIssuingBank.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtIssuingBank.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtIssuingBank.ControlStyle.CssClass = "";
        }
        //Card 1
        if (rfvCardNo1.Enabled && rfvCardNo1.ValidationGroup == strValidationGroup)
        {
            rfvCardNo1.Validate();
            if (rfvCardNo1.IsValid == false)
            {
                txtCardNo1.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtCardNo1.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtCardNo1.ControlStyle.CssClass = "";
        }

        if (revCardNo1.Enabled && revCardNo1.ValidationGroup == strValidationGroup)
        {
            if (rfvCardNo1.IsValid)
            {
                revCardNo1.Validate();
                if (revCardNo1.IsValid == false)
                {
                    txtCardNo1.ControlStyle.CssClass = "validationError";
                }
                else
                {
                    txtCardNo1.ControlStyle.CssClass = "";
                }
            }
        }
        else
        {
            txtCardNo1.ControlStyle.CssClass = "";
        }
        //Card 2
        if (rfvCardNo2.Enabled && rfvCardNo2.ValidationGroup == strValidationGroup)
        {
            rfvCardNo2.Validate();
            if (rfvCardNo2.IsValid == false)
            {
                txtCardNo2.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtCardNo2.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtCardNo2.ControlStyle.CssClass = "";
        }

        if (revCardNo2.Enabled && revCardNo2.ValidationGroup == strValidationGroup)
        {
            if (rfvCardNo2.IsValid)
            {
                revCardNo2.Validate();
                if (revCardNo2.IsValid == false)
                {
                    txtCardNo2.ControlStyle.CssClass = "validationError";
                }
                else
                {
                    txtCardNo2.ControlStyle.CssClass = "";
                }
            }
        }
        else
        {
            txtCardNo2.ControlStyle.CssClass = "";
        }
        //Card 3
        if (rfvCardNo3.Enabled && rfvCardNo3.ValidationGroup == strValidationGroup)
        {
            rfvCardNo3.Validate();
            if (rfvCardNo3.IsValid == false)
            {
                txtCardNo3.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtCardNo3.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtCardNo3.ControlStyle.CssClass = "";
        }

        if (revCardNo3.Enabled && revCardNo3.ValidationGroup == strValidationGroup)
        {
            if (rfvCardNo3.IsValid)
            {
                revCardNo3.Validate();
                if (revCardNo3.IsValid == false)
                {
                    txtCardNo3.ControlStyle.CssClass = "validationError";
                }
                else
                {
                    txtCardNo3.ControlStyle.CssClass = "";
                }
            }
        }
        else
        {
            txtCardNo3.ControlStyle.CssClass = "";
        }
        //Card 4
        if (rfvCardNo4.Enabled && rfvCardNo4.ValidationGroup == strValidationGroup)
        {
            rfvCardNo4.Validate();
            if (rfvCardNo4.IsValid == false)
            {
                txtCardNo4.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtCardNo4.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtCardNo4.ControlStyle.CssClass = "";
        }

        if (revCardNo4.Enabled && revCardNo4.ValidationGroup == strValidationGroup)
        {
            if (rfvCardNo4.IsValid)
            {
                revCardNo4.Validate();
                if (revCardNo4.IsValid == false)
                {
                    txtCardNo4.ControlStyle.CssClass = "validationError";
                }
                else
                {
                    txtCardNo4.ControlStyle.CssClass = "";
                }
            }
        }
        else
        {
            txtCardNo4.ControlStyle.CssClass = "";
        }

        //CardType
        if (rfvCardType.Enabled && rfvCardType.ValidationGroup == strValidationGroup)
        {
            rfvCardType.Validate();
            if (rfvCardType.IsValid == false)
            {
                lblVisa.ControlStyle.CssClass = "validationError";
                lblMasterCard.ControlStyle.CssClass = "validationError";

            }
            else
            {
                lblVisa.ControlStyle.CssClass = "";
                lblMasterCard.ControlStyle.CssClass = "";
            }
        }
        else
        {
            lblVisa.ControlStyle.CssClass = "";
            lblMasterCard.ControlStyle.CssClass = "";

        }

        #endregion

        #region Travellers Info


        if (rfvNameInsured.Enabled && rfvNameInsured.ValidationGroup == strValidationGroup)
        {
            rfvNameInsured.Validate();
            if (rfvNameInsured.IsValid == false)
            {
                txtNameInsured.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtNameInsured.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtNameInsured.ControlStyle.CssClass = "";
        }

        if (revNameInsured.Enabled && revNameInsured.ValidationGroup == strValidationGroup)
        {
            if (rfvNameInsured.IsValid)
            {
                revNameInsured.Validate();
                if (revNameInsured.IsValid == false)
                {
                    txtNameInsured.ControlStyle.CssClass = "validationError";
                }
                else
                {
                    txtNameInsured.ControlStyle.CssClass = "";
                }
            }
        }
        else
        {
            txtNameInsured.ControlStyle.CssClass = "";
        }

        if (rfvNameAdult2orSpouse.Enabled && rfvNameAdult2orSpouse.ValidationGroup == strValidationGroup)
        {
            rfvNameAdult2orSpouse.Validate();
            if (rfvNameAdult2orSpouse.IsValid == false)
            {
                txtNameAdult2orSpouse.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtNameAdult2orSpouse.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtNameAdult2orSpouse.ControlStyle.CssClass = "";
        }

        if (revNameAdult2orSpouse.Enabled && revNameAdult2orSpouse.ValidationGroup == strValidationGroup)
        {
            if (rfvNameAdult2orSpouse.IsValid)
            {
                revNameAdult2orSpouse.Validate();
                if (revNameAdult2orSpouse.IsValid == false)
                {
                    txtNameAdult2orSpouse.ControlStyle.CssClass = "validationError";
                }
                else
                {
                    txtNameAdult2orSpouse.ControlStyle.CssClass = "";
                }
            }
        }
        else
        {
            txtNameAdult2orSpouse.ControlStyle.CssClass = "";
        }


        ddlGenderInsured.ChangeValidationEffectServerSide(strValidationGroup);
        ddlGenderAdult2orSpouse.ChangeValidationEffectServerSide(strValidationGroup);
        ddlGenderChild1.ChangeValidationEffectServerSide(strValidationGroup);
        ddlGenderChild2.ChangeValidationEffectServerSide(strValidationGroup);
        ddlGenderChild3.ChangeValidationEffectServerSide(strValidationGroup);
        ddlGenderChild4.ChangeValidationEffectServerSide(strValidationGroup);
        ddlGenderChild5.ChangeValidationEffectServerSide(strValidationGroup);
        ddlGenderChild6.ChangeValidationEffectServerSide(strValidationGroup);

        #endregion


    }

    private void ClearSession()
    {
        Session[General.TAPersonnelId] = null;
        //Session[General.TAId] = null;
        //Session[General.TAResultId] = null;
    }

    private void ChangeDateSettings()
    {

        usrDOBInsured.StartYear = CE.Global.General.GetUTCDateTime().Year - 100;
        usrDOBInsured.EndYear = CE.Global.General.GetUTCDateTime().Year - 18;


    }

    protected void ibtnBack_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("~/travel-insurance/taresultsquotesone.aspx");
    }

    protected void csvCreditCardValid_ServerValidate(object source, ServerValidateEventArgs args)
    {
        bool _status = true;

        string _first = "";

        if (txtCardNo1.Text.Length > 0)
        {
            _first = txtCardNo1.Text.Trim().Substring(0, 1);
        }
        if (rdoVisa.Checked)
        {
            if (_first != "4")
            {
                _status = false;
            }
        }
        else if (rdoMasterCard.Checked)
        {
            if (_first != "5")
            {
                _status = false;
            }
        }
        if (_status == true)
        {
            txtCreditCardValid.Text = "";
            txtCreditCardValid.Text = txtCardNo1.Text.Trim() + "" + txtCardNo2.Text.Trim() + "" + txtCardNo3.Text.Trim() + "" + txtCardNo4.Text.Trim();
            string _cardNumer = txtCreditCardValid.Text;
            MySecurity _mysecurity = new MySecurity();
            if (_mysecurity.IsCreditCardValid(_cardNumer))
            {
                args.IsValid = true;
            }
            else
            {
                args.IsValid = false;
            }
        }
        else
        {
            args.IsValid = false;
        }
    }

    protected void csvCCExpiredValid_ServerValidate(object source, ServerValidateEventArgs args)
    {
        txtCCExpiredValid.Text = "";
        txtCCExpiredValid.Text = "valid";
        Int32 _Year = Convert.ToInt32(ddlCardExpiryYear.Text);
        Int32 _Month = Convert.ToInt32(ddlCardExpiryMonth.Text);

        MySecurity _mysecurity = new MySecurity();
        if (_mysecurity.IsCreditCardExpiredDateValid(_Year, _Month))
        {
            args.IsValid = true;
        }
        else
        {
            args.IsValid = false;
        }
    }

    private void ProposalNotification()
    {
        string _strSql, _providerName, _providerEmail, _providerCCEmail, _providerBCCEmail, _Date, _Time, _InsuranceName, _RefNo;
        MyDatabase _db = new MyDatabase();
        DataTable _dtProvider = new DataTable();
        DataTable _dtInsurance = new DataTable();
        _Date = "";
        _Time = "";
        _RefNo = "";
        _strSql = "";
        _providerName = "";
        _providerEmail = "";
        _providerCCEmail = "";
        _providerBCCEmail = "";

        _InsuranceName = "Travel Insurance";
        _strSql = "SELECT [CompanyName], [Email1] FROM tblProviderCompany WHERE ProviderCompanyId = " + Session[CE.Global.General.ProviderCompanyId].ToString();
        _dtProvider = _db.GetDataTable(_strSql);

        if (_dtProvider.Rows.Count > 0)
        {
            _providerName = _dtProvider.Rows[0]["CompanyName"].ToString();
        }

        _providerEmail = CE.Configuration.MyConfigurationManager.GetAppSettingValue("LibertyTI_TO");
        _providerCCEmail = CE.Configuration.MyConfigurationManager.GetAppSettingValue("LibertyTI_CC");
        _providerBCCEmail = CE.Configuration.MyConfigurationManager.GetAppSettingValue("LibertyTI_BCC");

        _strSql = "";
        _strSql = "SELECT CONVERT(VARCHAR,ModifiedDate,103) AS [Date], CONVERT(VARCHAR,ModifiedDate,108) AS [Time] ";
        _strSql += " FROM  tblTAMoreDetail_Liberty WHERE Info2 = " + Session[General.TAId].ToString() + " ORDER BY ModifiedDate DESC";
        _dtInsurance = _db.GetDataTable(_strSql);
        if (_dtInsurance.Rows.Count > 0)
        {
            _Date = _dtInsurance.Rows[0]["Date"].ToString();
            _Time = _dtInsurance.Rows[0]["Time"].ToString();
        }
        string convertno = General.GetRefNumber(Convert.ToInt64(Session[General.TAId].ToString()));
        _RefNo = "TIL" + convertno;

        if ((_dtProvider.Rows.Count > 0) && (_dtInsurance.Rows.Count > 0))
        {
            MyMailManager.SendProposalCompleteNotification(_providerName, _providerEmail, _providerCCEmail, _providerBCCEmail, _InsuranceName, _Date, _Time, _RefNo);
        }

    }

    protected void txtPostCode_TextChanged(object sender, EventArgs e)
    {
        GetPostCode();
    }

    protected void ddlAddressList_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlAddressList.Items.Count > 0 && ddlAddressList.SelectedIndex >= 0)
        {
            txtAddress.Text = ddlAddressList.Text;
        }
    }

    protected void ibtPostCode_Click(object sender, ImageClickEventArgs e)
    {
        GetPostCode();
    }

    private void GetPostCode()
    {
        rfvPostCode.Validate();
        revPostCode.Validate();
        if (rfvPostCode.IsValid && revPostCode.IsValid)
        {
            txtPostCode.ControlStyle.CssClass = "";
            txtAddress.ControlStyle.CssClass = "";
            MyLocation _myLoc = new MyLocation();
            //string _strAddress = _myLoc.GetAddressByPostCode(txtPostCode.Text);
            //if (_strAddress != null && _strAddress != string.Empty)
            //{
            //    if (_strAddress.ToLower().Contains("invalid api"))
            //    {
            //        txtAddress.Text = "Address can't be retrieved. Please type your address detail here.";
            //    }
            //    else
            //    {
            //        txtAddress.Text = _strAddress;
            //    }
            //}
            //else
            //{
            //    txtAddress.Text = "Address is not found.";
            //}

            System.Data.DataSet _ds = _myLoc.GetAddressByPostCodeDataSet(txtPostCode.Text);
            ddlAddressList.Items.Clear();
            string _lstValue;
            string _lstText;
            int _rowCount = 0;

            if (_ds != null)
            {
                if (_ds.Tables.Count > 0)
                {
                    foreach (System.Data.DataTable _dt in _ds.Tables)
                    {
                        if (_dt.Rows.Count > 0 && _dt.Columns.Count >= 2)
                        {
                            foreach (System.Data.DataRow _dr in _dt.Rows)
                            {
                                //lblAddress2.Text += _dr["t"].ToString() + "<br />";
                                //lblAddress2.Text += _dr["a"].ToString() + "<br /><br />";
                                if (_dr["t"] != null && _dr["a"] != null)
                                {
                                    _lstValue = _dr["t"].ToString() + ", " + _dr["a"].ToString();
                                    _lstText = _dr["t"].ToString();
                                    ddlAddressList.Items.Add(new ListItem(_lstText, _lstValue));
                                    if (_rowCount == 0)
                                    {
                                        txtAddress.Text = _lstValue;
                                        //ibtPostCode.Enabled = false;
                                        txtAddress.ReadOnly = true;
                                    }

                                    _rowCount++;
                                }
                            }
                        }
                        else
                        {
                            txtAddress.Text = "Confirm postcode or enter manually.";
                            txtAddress.ReadOnly = false;
                            txtAddress.ControlStyle.CssClass = "validationError";
                        }
                    }
                }
                else
                {
                    txtAddress.Text = "Confirm postcode or enter manually.";
                    txtAddress.ReadOnly = false;
                    txtAddress.ControlStyle.CssClass = "validationError";
                }
            }
            else
            {
                txtAddress.Text = "Please type your address here.";
                txtAddress.ReadOnly = false;
                txtAddress.ControlStyle.CssClass = "validationError";
            }

            if (_rowCount > 1)
            {
                divAddressList.Visible = true;
            }
            else
            {
                divAddressList.Visible = false;

            }
        }
        else
        {
            txtPostCode.ControlStyle.CssClass = "validationError";
            ddlAddressList.Items.Clear();
            divAddressList.Visible = false;
            txtAddress.Text = "Invalid postcode.";
            txtAddress.ControlStyle.CssClass = "validationError";
        }
    }

    private void ShowUserDetails()
    {
        //hplEditProfile.Visible = true;
        CE.User.Profile _profile = new CE.User.Profile();
        CE.User.ProfileDB _profiledb = new ProfileDB();
        CE.User.Contact _contact = new Contact();
        CE.User.ContactDB _contactdb = new ContactDB();

        Int64 UserId = Convert.ToInt64(Session[General.UserId].ToString());
        _profile = _profiledb.GetProfile(UserId);
        if (_profile != null)
        {
            txtFullname.Text = _profile.FirstName + " " + _profile.SurName;

            //usrDOBInsured.Day = _profile.DOB.Day; //Sakthi on 03 Dec 2010
            //usrDOBInsured.Month = _profile.DOB.Month;
            //usrDOBInsured.Year = _profile.DOB.Year;
            usrDOB.Day = _profile.DOB.Day;
            usrDOB.Month = _profile.DOB.Month;
            usrDOB.Year = _profile.DOB.Year;

            if (_profile.IDNo.Length == 9)
            {
                //txtNRICPass.Text = _profile.IDNo[0].ToString() + _profile.IDNo[8].ToString() + _profile.IDNo.Substring(1, 7);
                ddlNRIC.Prefix = _profile.IDNo[0].ToString();
                ddlNRIC.Postfix = _profile.IDNo[8].ToString();
                ddlNRIC.IDNumber = _profile.IDNo.Substring(1, 7);
            }
            if (_profile.Nationality != "")
            {
                ddlNationality.Nationality = _profile.Nationality.ToString();
            }

            _contact = _contactdb.GetContact(UserId);
            if (_contact != null)
            {
                txtMobileNo.PhoneNo = _contact.Mobile;
                txtOfficeNo.PhoneNo = _contact.OfficePhone;
                txtEmailAddress.Text = _contact.Email.ToString();

            }

            _profile = null;
            _profiledb = null;
            _contact = null;
            _contactdb = null;

        }
    }

    private void ValidateChild1(bool OnOff)
    {
        rfvChildName1.Enabled = OnOff;
        revChildName1.Enabled = OnOff;
        ddlChildNRIC1.IsEnableValidation(OnOff);
        ddlChildDOB1.IsEnableValidation(OnOff);
        ddlChildNationality1.IsEnableValidation(OnOff);
        ddlChildRelationship1.IsEnableValidation(OnOff);
        ddlGenderChild1.IsEnableValidation(OnOff);
    }

    private void ValidateChild2(bool OnOff)
    {
        rfvChildName2.Enabled = OnOff;
        revChildName2.Enabled = OnOff;
        ddlChildNRIC2.IsEnableValidation(OnOff);
        ddlChildDOB2.IsEnableValidation(OnOff);
        ddlChildNationality2.IsEnableValidation(OnOff);
        ddlChildRelationship2.IsEnableValidation(OnOff);
        ddlGenderChild2.IsEnableValidation(OnOff);
    }

    private void ValidateChild3(bool OnOff)
    {
        rfvChildName3.Enabled = OnOff;
        revChildName3.Enabled = OnOff;
        ddlChildNRIC3.IsEnableValidation(OnOff);
        ddlChildDOB3.IsEnableValidation(OnOff);
        ddlChildNationality3.IsEnableValidation(OnOff);
        ddlChildRelationship3.IsEnableValidation(OnOff);
        ddlGenderChild3.IsEnableValidation(OnOff);
    }

    private void ValidateChild4(bool OnOff)
    {
        rfvChildName4.Enabled = OnOff;
        revChildName4.Enabled = OnOff;
        ddlChildNRIC4.IsEnableValidation(OnOff);
        ddlChildDOB4.IsEnableValidation(OnOff);
        ddlChildNationality4.IsEnableValidation(OnOff);
        ddlChildRelationship4.IsEnableValidation(OnOff);
        ddlGenderChild4.IsEnableValidation(OnOff);
    }

    private void ValidateChild5(bool OnOff)
    {
        rfvChildName5.Enabled = OnOff;
        revChildName5.Enabled = OnOff;
        ddlChildNRIC5.IsEnableValidation(OnOff);
        ddlChildDOB5.IsEnableValidation(OnOff);
        ddlChildNationality5.IsEnableValidation(OnOff);
        ddlChildRelationship5.IsEnableValidation(OnOff);
        ddlGenderChild5.IsEnableValidation(OnOff);
    }

    private void ValidateChild6(bool OnOff)
    {
        rfvChildName6.Enabled = OnOff;
        revChildName6.Enabled = OnOff;
        ddlChildNRIC6.IsEnableValidation(OnOff);
        ddlChildDOB6.IsEnableValidation(OnOff);
        ddlChildNationality6.IsEnableValidation(OnOff);
        ddlChildRelationship6.IsEnableValidation(OnOff);
        ddlGenderChild6.IsEnableValidation(OnOff);
    }

    protected void imgbtnBackTop_Click(object sender, ImageClickEventArgs e)
    {
        if (Request.QueryString["p"] != null)
        {
            Response.Redirect("~/promo/liberty-august-travel-insurance-results.aspx");
        }
        else
        {
            if (Session["TAFromSummary"] != null)
            {
                if (Session["TAFromSummary"].ToString().Trim() == "1")
                {
                    BackToResultsMain();
                }
                else
                {
                    BackToResultsDetails();
                }
            }
            else
            {
                BackToResultsMain();
            }
        }
    }

    private void BackToResultsMain()
    {
        if (Request.QueryString["pid"] != null)
        {
            if (Request.QueryString["pid"].ToString() != "")
            {
                Response.Redirect("~/travel-insurance/results.aspx?pid=" + Request.QueryString["pid"].ToString());
            }
            else
            {
                Response.Redirect("~/travel-insurance/results.aspx");
            }
        }
        else
        {
            Response.Redirect("~/travel-insurance/results.aspx");
        }
    }

    private void BackToResultsDetails()
    {
        if (Request.QueryString["pid"] != null)
        {
            if (Request.QueryString["pid"].ToString() != "")
            {
                Response.Redirect("~/travel-insurance/results-details.aspx?pid=" + Request.QueryString["pid"].ToString());
            }
            else
            {
                Response.Redirect("~/travel-insurance/results-details.aspx");
            }
        }
        else
        {
            Response.Redirect("~/travel-insurance/results-details.aspx");
        }
    }

}
